﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using STDTO.DataTransferObjects.Base;
using STDTO.DataTransferObjects.Unit.Tests.Interfaces;
using System.Runtime.Serialization;
using STDTO.DataTransferObjects.Interfaces;
using Microsoft.Practices.Unity;

namespace STDTO.DataTransferObjects.Unit.Tests.DTOs
{
    [DataContract]
    class ObjectContainsListOfSimpleObjectDto: UnitySelfTrackingDataTransferObjectBase<IObjectContainsListOfSimpleObjects>, IObjectContainsListOfSimpleObjects
    {

        public ObjectContainsListOfSimpleObjectDto(IUnityContainer unityContainer):base(unityContainer){ }

        #region ISimpleObject Members
        [DataMember]
        private int _Id;
        [DataMember]
        private IList<ISimpleObject> _SimpleObjects;
   

        public int Id
        {
            get
            {
                return _Id;
            }
            set
            {
                Set("Id", ref _Id, value);
            }
        }

       
        public IList<ISimpleObject> SimpleObjects
        {
            get
            {
                return _SimpleObjects;
            }
            set
            {
                Set("SimpleObjects", ref _SimpleObjects, value); ;
            }
        }

        #endregion

        protected override void SpecificPopulate(IObjectContainsListOfSimpleObjects entity, IDataTrasferObjectToEntityMapper dataTrasferObjectToEntityMapper)
        {
            _Id = entity.Id;
            _SimpleObjects = CreateCollectionDtoInner<ISimpleObject>(entity.SimpleObjects, dataTrasferObjectToEntityMapper);
            
        }

        protected override void SpecificGetValue(IObjectContainsListOfSimpleObjects entity, bool getOriginalValue, IDataTrasferObjectToEntityMapper dataTrasferObjectToEntityMapper)
        {
            entity.Id = RetrievePropertyValue<int>("Id", getOriginalValue);
            entity.SimpleObjects = ((ISelfTrackingDataTransferObjectEx<IList<ISimpleObject>>)SimpleObjects).Clone(getOriginalValue, dataTrasferObjectToEntityMapper);
            
        }

        protected override void SpecificApplyChanges(IObjectContainsListOfSimpleObjects entity, IDataTrasferObjectToEntityMapper dataTrasferObjectToEntityMapper)
        {
            ((ISelfTrackingDataTransferObjectEx<IList<ISimpleObject>>)SimpleObjects).ApplyChanges(entity.SimpleObjects, dataTrasferObjectToEntityMapper);
        }	 
    
    }
}
